using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DevExpress.XtraTreeList.Nodes;

using DevExpress.XtraEditors;
using TierService;
using TierApplication;

namespace OrderMgr.Rpt
{
    public partial class frmRptSupplierPay : TierService.frmTemplate
    {
        #region "Variable"
        DataSet dsDepartment = new DataSet();
        SqlDataAdapter sdaDepartment = new SqlDataAdapter();
        #endregion
        public frmRptSupplierPay()
        {
            InitializeComponent();
        }

        private void BindGrid()
        {


            string ls_where = "";

            if ((txtSupplierID.Text.Trim() != "") && (ckbSupplierID.Checked))
                ls_where = ls_where + " and a.SupplierID = '" + (string)txtSupplierID.EditValue + "'";

            //if ((ckbOrderDate.Checked) && (txtOrderDateStart.Text != "") && (txtOrderDateEnd.Text != ""))
            //{
            //    ls_where = ls_where + " and Convert(varchar(10),a.PayDate,120) >='" + txtOrderDateStart.DateTime.ToString("yyyy-MM-dd") + "'";
            //    ls_where = ls_where + " and Convert(varchar(10),a.PayDate,120) <='" + txtOrderDateEnd.DateTime.ToString("yyyy-MM-dd") + "'";
            //}

            T_Supplier mSupplier = new T_Supplier();

            gcSupplier.DataSource = mSupplier.GetPayList(ls_where).Tables[0];
       
        }

        private void frmSupplierPay_Load(object sender, EventArgs e)
        {
            Utility.DataToLookupComboxEx(txtSupplierID, (new T_Supplier()).GetList(""), "SupplierID", "SupplierName");
            //Utility.DataToLookupComboxEx(txtPayUserID, (new P_User()).GetList(""), "UserID", "UserName");
        }


        private void btnQuit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void gvSupplier_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
            if (e.Info.IsRowIndicator)
            {
                if (e.RowHandle >= 0)
                {
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
                }
                else if (e.RowHandle < 0 && e.RowHandle > -1000)
                {
                    e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;
                    e.Info.DisplayText = "G" + e.RowHandle.ToString();
                }
            }
        }

        private void gvSupplier_DoubleClick(object sender, EventArgs e)
        {
            //if (gvSupplier.RowCount < 1) return;
            //DataRow dr = gvSupplier.GetDataRow(gvSupplier.FocusedRowHandle);
            //string sID = dr["SupplierPayID"].ToString();


            //frmSupplierPayDetail fDetail = new frmSupplierPayDetail();
            //fDetail._SupplierPayID = sID;
            //fDetail.OpMode = TierService.Utility.OperateMode.Query;
            //fDetail.ShowDialog();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            BindGrid();
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            if (gvSupplier.RowCount < 1) return;
            DataRow dr = gvSupplier.GetDataRow(gvSupplier.FocusedRowHandle);
            string sID = dr["SupplierID"].ToString();

            CustomerInfo.frmSupplierPay fDetail = new CustomerInfo.frmSupplierPay();
            fDetail._SupplierID = sID;
            if ((ckbOrderDate.Checked) && (txtOrderDateStart.Text != "") && (txtOrderDateEnd.Text != ""))
            {
                fDetail._StartDate = txtOrderDateStart.Text;
                fDetail._EndDate = txtOrderDateEnd.Text;
            }
            fDetail.ShowDialog();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (gvSupplier.RowCount < 1) return;
            DataRow dr = gvSupplier.GetDataRow(gvSupplier.FocusedRowHandle);
            string sID = dr["SupplierID"].ToString();

            OrderInfo.frmBuySearchByProduct fDetail = new OrderInfo.frmBuySearchByProduct();
            fDetail._SupplierID = sID;
            if ((ckbOrderDate.Checked) && (txtOrderDateStart.Text != "") && (txtOrderDateEnd.Text != ""))
            {
                fDetail._StartDate = txtOrderDateStart.Text;
                fDetail._EndDate = txtOrderDateEnd.Text;
            }
            fDetail.ShowDialog();
        }


    }
}